package com.ea.eadp.nexus.test.pageDefinition.gameconnect;

import com.ea.eadp.nexus.test.common.PageOperation;
import com.ea.eadp.nexus.test.pageDefinition.BasePage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;


public class GameConnectSigninPage extends BasePage {
    public GameConnectSigninPage(WebDriver driver) {
        super(driver, GameConnectSigninPage.class);
    }

    public void navigate(String uri) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(uri);
        driver.navigate().to(uri);
    }

    public void setEmail(String email) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(email);
        PageOperation.SendKeyToElementAfterWait(driver, "email", email);
    }

    public void setPassword(String password) {
        driver.switchTo().window(this.operationWindowHandle);
        PageOperation.SendKeyToElementAfterWait(driver, "password", password);
    }

    public void setTwoFactorCode(String twoFactorCode) {
        driver.switchTo().window(this.operationWindowHandle);
        PageOperation.SendKeyToElementAfterWait(driver, "twoFactorCode", twoFactorCode);
    }

    public void setTrustThisDevice(boolean check) {
        driver.switchTo().window(this.operationWindowHandle);
        PageOperation.SelectCheckboxAfterWait(driver, "trustThisDevice", "label-trustThisDevice", check);
    }

    public void setOriginId(String originId) {
        driver.switchTo().window(this.operationWindowHandle);
        PageOperation.SendKeyToElementAfterWait(driver, "originId", originId);
    }

    public void switchEntries() {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//div[@id='panel-login']/div[1]/div[4]/p[2]/a")).click();
        driver.findElement(By.xpath("//form[@id='regForm']/div[2]/div[4]/p[2]/a")).click();
    }

    public String getMessageByXPath(String xpath) {
        driver.switchTo().window(this.operationWindowHandle);
        return driver.findElement(By.xpath(xpath)).getText();
    }

    public void clickToSignIn() {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//div[@id='panel-login']/div[4]/div[2]/a/span/span")).click();
    }

    public void clickToLink() {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//div[@id='panel-profile-confirmation']/div[4]/div[2]/a/span/span")).click();
    }

    public void clickToSignInTFA() {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//a[@id='btnTFALogin']/span/span")).click();
    }

    public void clickToResendTFA() {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//a[@id='resend_code_link']")).click();
    }

    public void clickToUpgrade() {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.xpath("//div[@id='panel-upgrade']/div/div/div[2]/a[1]/span/span")).click();
    }
}

